<%--
  Created by IntelliJ IDEA.
  User: simba
  Date: 2021/3/21
  Time: 10:24 下午
  To change this template use File | Settings | File Templates.
--%>
<% String path = request.getContextPath(); %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录</title>
</head>

<body>

<form method="post" id="loginForm" action="<%=path%>/LoginServlet">
    <center>

        <input type="text" id="username" name="username" value="${username}" placeholder="用户名"/>
        <input type="text" id="password" name="password" placeholder="密码"/>
        <button type="button" name="loginBtn" onclick="loginVerify()">登 录</button>
        <button type="reset">重置</button>
        ${error}
    </center>

</form>
</body>
</html>

<script>

    //登录验证
    function loginVerify() {
        var username = document.getElementById("username").value;
        var password = document.getElementById("password").value;
        if (username == '') {
            alert("用户名不能为空");
            return;
        }
        if (password == '') {
            alert("密码不能为空");
            return;
        }

        //调用后端Servlet，并传递数据
        document.getElementById("loginForm").submit();
    }

</script>

